package com.mq.config;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeoutException;

/**
 * 连接工具
 */
public class ConnectUtils {

    public static Connection getConnect() throws IOException, TimeoutException, NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
        //1. 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2. 设置连接配置
        factory.setUsername("zhangsan");
        factory.setPassword("123456");
        factory.setHost("服务器IP");
        factory.setVirtualHost("/shop");
        factory.setPort(5672);
        //3.创建连接
        return factory.newConnection();
    }

    public static void main(String[] args) throws URISyntaxException, KeyManagementException, TimeoutException, NoSuchAlgorithmException, IOException {
        Connection connect = ConnectUtils.getConnect();
        System.out.println(connect);
    }
}
